// const { override, fixBabelImports } = require('customize-cra');
// module.exports = function override(config, env) {
//   // do stuff with the webpack config...
//   return config;
// };
// module.exports = override(
//   fixBabelImports('import', {
//     libraryName: 'antd-mobile',
//     style: 'css',
//   }),
// );

const {
  override,
  fixBabelImports,
  addLessLoader,
  addWebpackPlugin,
  addWebpackAlias,
} = require('customize-cra');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const path = require("path");
if (process.env.NODE_ENV === 'development') {
  process.env.GENERATE_SOURCEMAP = "true";
} else if (process.env.NODE_ENV === 'production') {
  process.env.GENERATE_SOURCEMAP = "false";
}
module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  }),
  addLessLoader({
      lessOptions: {
          javascriptEnabled: true,
          modifyVars: {
              '@primary-color': '#1DA57A'
          },
      },
  }),
  addWebpackAlias({ //配置路径别名
      ["@"]: path.resolve(__dirname, "src")
  }),
  addWebpackPlugin((config) => {
      config.options.plugins.push(new AntdDayjsWebpackPlugin()); //替换moment包
      config.options.plugins.push( //打包开启gzip的压缩
          new CompressionWebpackPlugin({
              filename: '[path].gz[query]',
              algorithm: 'gzip',
              test: /\.js$|\.css$|\.html$/,
              threshold: 10240,
              minRatio: 0.8,
          })
      )
  })
)
